﻿// Copyright (c) 2009, 3G.cn
// $Author: Moweiqiang $
// $Date: 09-01-23 17:43 $
// $Revision: 1 $
// $NoKeywords: $
namespace Jiubang.Collections {
	using System.Collections.Generic;

	/// <summary>
	/// 任意两个比较的值不会相等。较后插入的值将视为较大。
	/// </summary>
	/// <typeparam name="T"></typeparam>
	internal class NoEqualComparer<T> : IComparer<T> {
		private readonly IComparer<T> compare;

		/// <param name="compare">该值为空时使用默认比较器</param>
		public NoEqualComparer(IComparer<T> compare) { this.compare = compare ?? Comparer<T>.Default; }

		#region IComparer<T> Members

		public int Compare(T x, T y) { return compare.Compare(x, y) >= 0 ? 1 : -1; }

		#endregion
	}
}